export default class Proxys {


    /**
     * 代理对象实例化
     * @param obj
     * @param ctx
     * @param handler
     * @returns {*}
     */
    static newProxyInstance(obj, ctx, handler) {
        //找到对象的所以方法
        let methods = Object.getOwnPropertyNames(obj);
        //遍历对象的所以方法
        for (let i = 0; i < methods.length; i++) {
            //找到构造方法排除掉

            if (methods[i] == "constructor") {
                
                continue;
            }

            //保留对象的最原始方法
            const method = obj[methods[i]];
            //方法增强
            Reflect.set(obj, methods[i], new Proxy(method, {
                apply(targetMethod, obj, argArray) {
                    return handler.invoke(obj, targetMethod, methods[i], argArray);
                }
            }))
        }
        return obj;
    }
}

